package com.coderman.infosys.auth.adapter.controller.role;

import com.coderman.infosys.auth.adapter.controller.BaseController;
import com.coderman.infosys.auth.adapter.convert.RoleConverter;
import com.coderman.infosys.auth.adapter.convert.RoleGroupConverter;
import com.coderman.infosys.auth.domain.bo.role.RoleBO;
import com.coderman.infosys.auth.domain.bo.role.RoleGroupBO;
import com.coderman.infosys.auth.domain.gataway.UserRoleQueryGataway;
import com.coderman.infosys.plat.auth.common.dto.ResultDataDto;
import com.coderman.infosys.plat.auth.common.page.PageBO;
import com.coderman.infosys.plat.auth.common.vo.PageVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.coderman.infosys.auth.adapter.vo.role.RoleVO;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.coderman.infosys.auth.domain.repository.UserRoleRepository;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


/**
* @Description:控制层
* @Author:
* @CreateTime:2022-01-04 15:27:39
* @version v1.0
*/
@RestController
public class RoleQueryController extends BaseController {
	
	protected Logger logger = LoggerFactory.getLogger(RoleQueryController.class);

	@Autowired
	private UserRoleQueryGataway userRoleQueryGataway;


	/**
	 *
	 * @Description 搜索
	 * @param search
	 * @return RoleVO
	 */
	@RequestMapping(value = "/role/search")
	public ResultDataDto<List<RoleVO>> getByRoleCode(@RequestParam(value = "search", required = true) String search){
		List<RoleBO> roleBOList = userRoleQueryGataway.searchRole(search);
		return ResultDataDto.success(RoleConverter.INSTANCE.boList2voList(roleBOList));
	}

	/**
	 *
	 * @Description 分页获取角色信息
	 * @param pageVO
	 * @return PageVO<RoleVO>
	 */
	@RequestMapping(value = "/role/pagelist")
	public ResultDataDto<PageVO> getPageList(@RequestParam(value = "pageVO", required = true) PageVO pageVO){
		PageBO pageBO = pageVO.convertToBO();
		List<RoleBO> roleBOList = userRoleQueryGataway.getRolePageList(pageBO);
		return ResultDataDto.success(pageVO.initData(RoleConverter.INSTANCE.boList2voList(roleBOList), pageBO.getTotalRows()));
	}
}
